package com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.mb_store_api_final.giftsandgoods.goods.entity.GgGoods;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.service.GgSupplierService;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.dao.GgSupplierDao;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.entity.GgSupplier;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.vo.GgGoodsListVo;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.vo.GgSupplierVo;

import com.javasm.mb_store_api_final.giftsandgoods.goodsType.entity.GgGoodsType;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品管理-供应商(GgSupplier)表服务实现类
 *
 * @author makejava
 * @since 2024-07-30 15:33:36
 */
@Service("ggSupplierService")
public class GgSupplierServiceImpl extends ServiceImpl<GgSupplierDao, GgSupplier> implements GgSupplierService {

    @Resource
    private GgSupplierDao ggSupplierDao;
    @Override
    public IPage<GgSupplier> listBySupplierNameAndContacts(GgSupplierVo supplierVo) {

        LambdaQueryWrapper<GgSupplier> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(supplierVo.getSupplierName()!=null&&!supplierVo.getSupplierName().equals("")){
            lambdaQueryWrapper.like(GgSupplier::getSupplierName,supplierVo.getSupplierName());
        }
        if(supplierVo.getContacts()!=null&&!supplierVo.getContacts().equals("")){
            lambdaQueryWrapper.like(GgSupplier::getContacts,supplierVo.getContacts());
        }
        if(supplierVo.getQuerySelect()!=null&&!supplierVo.getQuerySelect().equals("")&&supplierVo.getQuerySelect().equals("supplierName")){
            lambdaQueryWrapper.like(GgSupplier::getSupplierName,supplierVo.getQueryInput());
        }
        if(supplierVo.getQuerySelect()!=null&&!supplierVo.getQuerySelect().equals("")&&supplierVo.getQuerySelect().equals("contacts")){
            lambdaQueryWrapper.like(GgSupplier::getContacts,supplierVo.getQueryInput());
        }
        if(supplierVo.getQuerySelect()!=null&&!supplierVo.getQuerySelect().equals("")&&supplierVo.getQuerySelect().equals("contactPhone")){
            lambdaQueryWrapper.like(GgSupplier::getContactPhone,supplierVo.getQueryInput());
        }
        if(supplierVo.getQuerySelect()!=null&&!supplierVo.getQuerySelect().equals("")&&supplierVo.getQuerySelect().equals("contactAddress")){
            lambdaQueryWrapper.like(GgSupplier::getContactAddress,supplierVo.getQueryInput());

        }
        if(supplierVo.getQuerySelect()!=null&&!supplierVo.getQuerySelect().equals("")&&supplierVo.getQuerySelect().equals("bankOfDeposit")){
            lambdaQueryWrapper.like(GgSupplier::getBankOfDeposit,supplierVo.getQueryInput());
        }
        if(supplierVo.getQuerySelect()!=null&&!supplierVo.getQuerySelect().equals("")&&supplierVo.getQuerySelect().equals("accountNo")){
            lambdaQueryWrapper.like(GgSupplier::getAccountNo,supplierVo.getQueryInput());
        }
        //分页
        IPage<GgSupplier> page = new Page<>(supplierVo.getPageNum(),supplierVo.getPageSize());
        page(page,lambdaQueryWrapper);
        return page;
    }

    @Override
    public List<GgGoods> getGgGoodsBySid(Integer sid) {
        List<GgGoods> ggGoods=ggSupplierDao.selectGoodsBySid(sid);
        return ggGoods;
    }

    @Override
    public void addGoodsByIdAndListGid(GgGoodsListVo goodsListVo) {
        String[] gids = goodsListVo.getListGid().split(",");
        for (String gid : gids) {
            ggSupplierDao.addGoodsByIdAndListGid(goodsListVo.getId(),Integer.parseInt(gid));
        }
    }
}

